package com._9xcloud.leaverequest.repository;

import com._9xcloud.leaverequest.domain.LeaveRequest;
import com._9xcloud.leaverequest.domain.LeaveRequestStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by hyq on 2015/5/24.
 */
public interface LeaveRequestRepository extends JpaRepository<LeaveRequest, Integer> {
    List<LeaveRequest> findByStudentId(int studentId);
    List<LeaveRequest> findByStudentIdAndStatus(int studentId, LeaveRequestStatus status);

    List<LeaveRequest> findByLessonId(int lessonId);
    List<LeaveRequest> findByLessonIdAndStatus(int lessonId, LeaveRequestStatus status);

    @Query("select l from LeaveRequest l left join l.student s where s.clazz.id=?1")
    List<LeaveRequest> findByClazzId(int clazzId);

    @Query("select l from LeaveRequest l left join l.student s where s.clazz.id=?1 and l.status=?2")
    List<LeaveRequest> findByClazzId(int clazzId, LeaveRequestStatus status);

    @Query("select l from LeaveRequest l left join l.lesson ls where ls.course.id=?1")
    List<LeaveRequest> findByCourseId(int courseId);

    @Query("select l from LeaveRequest l left join l.lesson ls where ls.course.id=?1 and l.status=?2")
    List<LeaveRequest> findByCourseId(int courseId, LeaveRequestStatus status);

    @Query("select l from LeaveRequest l left join l.student s where s.clazz.college.id=?1")
    List<LeaveRequest> findByCollegeId(int collegeId);

    @Query("select l from LeaveRequest l left join l.student s where s.clazz.college.id=?1 and l.status=?2")
    List<LeaveRequest> findByCollegeId(int collegeId, LeaveRequestStatus status);
}
